package com.yuyou.hxyy.gateway.security;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;

import com.yuyou.hxyy.service.api.security.SecurityCons;
import com.yuyou.hxyy.service.api.vo.resp.RespLogin;


public class UserDetailsImpl implements UserDetails {
	private String userName;
	private String password;
	private Integer role;

	private RespLogin resp;

	public RespLogin getResp() {
		return resp;
	}

	public void setResp(RespLogin resp) {
		this.resp = resp;
	}



	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Integer getRole() {
		return role;
	}

	public void setRole(Integer role) {
		this.role = role;
	}

	public UserDetailsImpl(String userName, String password, Integer role) {
		this.userName = userName;
		this.password = password;
		this.role = role;
	}

	private static final long serialVersionUID = -1922135614793714181L;

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		StringBuilder commaBuilder = new StringBuilder();
		commaBuilder.append(SecurityCons.role.getNameByType(role));
		return AuthorityUtils.commaSeparatedStringToAuthorityList(commaBuilder
				.toString());
	}

	@Override
	public String getPassword() {
		return this.password;
	}

	@Override
	public String getUsername() {
		return this.userName;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

}